//
//  MQNavigationController.swift
//  MQWeibo
//
//  Created by 毛强 on 15/12/27.
//  Copyright © 2015年 itheima. All rights reserved.
//

import UIKit

class MQNavigationController: UINavigationController {
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        if childViewControllers.count > 0 {
            var backTitle = "返回"
            if childViewControllers.count == 1
            {
                backTitle = childViewControllers.first?.title ?? "返回"
            }
            
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(imageName: "navigationbar_back_withtext", title: backTitle, target: self, action: "back")
            
            viewController.hidesBottomBarWhenPushed = true
        }
        
        super.pushViewController(viewController, animated: true)
    }
    
    @objc private func back(){
        popViewControllerAnimated(true)
    }
}
